﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CommonUtils;
using BusinessLogicLayer;
using Resources;

namespace LiveCPEProject
{
    public partial class MyMaster : MasterPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            initUserPersonnalFields();
        }

        private void initUserPersonnalFields()
        {
            if (!Context.User.Identity.IsAuthenticated)
            {
                UserFace.ImageUrl = "~/img/john_smith.png";
            }
            else
            {
                UserFace.ImageUrl = "displayimg?userName="+Context.User.Identity.Name;
            }

            if (Context.User.Identity.IsAuthenticated)
            {
                Label lbl = (Label)LoginViewUserName.FindControl("CurrentUserName");
                if (lbl != null)
                {
                    lbl.Text = Context.User.Identity.Name;
                }
            }
        }

        protected void TextBoxSearch_Changed(object sender, EventArgs e)
        {
            try
            {
                TextBox tb = (sender as TextBox);
                Button bt = ControlFinder.FindControl<Button>(this, "ButtonSearch");
                if (bt != null)
                {
                    bt.CommandArgument = tb.Text;
                }
            }
            catch (Exception ee)
            {
                System.Diagnostics.StackFrame sf = new System.Diagnostics.StackFrame();
                LogWriter.AddLog(ee, LogStatus.Error, GlobalParameters.ApplicationDisplayName, sf.GetMethod().Name);
                throw new Exception(sf.GetMethod().Name + " unexpected error", ee);
            }
        }

        protected void OpenPanel_Click(object sender, EventArgs e)
        {
            try
            {
                sender.ToString();
                //Response.Write(@"jQuery((function () { var dlg = jQuery('#dialog').dialog({ autoOpen: true, modal: true, width: 400, resizable: false, overlay: { background: 'black', opacity: 0.5 } }); dlg.parent().appendTo(jQuery('form:first')); });");
            }
            catch (Exception ee)
            {
                System.Diagnostics.StackFrame sf = new System.Diagnostics.StackFrame();
                LogWriter.AddLog(ee, LogStatus.Error, GlobalParameters.ApplicationDisplayName, sf.GetMethod().Name);
                throw new Exception(sf.GetMethod().Name + " unexpected error", ee);
            }
        }

        protected void SendPrivateMessage_Click(object sender, EventArgs e)
        {
            try
            {
                Button bt = (sender as Button);
                String messageId = bt.CommandArgument;
            }
            catch (Exception ee)
            {
                System.Diagnostics.StackFrame sf = new System.Diagnostics.StackFrame();
                LogWriter.AddLog(ee, LogStatus.Error, GlobalParameters.ApplicationDisplayName, sf.GetMethod().Name);
                throw new Exception(sf.GetMethod().Name + " unexpected error", ee);
            }
        }

        protected void ButtonSearchAction(object sender, EventArgs e)
        {
            try
            {
                Button bt = (sender as Button);
                Response.Redirect("~/wall/Wall.aspx?userName=" + bt.CommandArgument);
            }
            catch (Exception ee)
            {
                System.Diagnostics.StackFrame sf = new System.Diagnostics.StackFrame();
                LogWriter.AddLog(ee, LogStatus.Error, GlobalParameters.ApplicationDisplayName, sf.GetMethod().Name);
                throw new Exception(sf.GetMethod().Name + " unexpected error", ee);
            }
        }
    }
}